package com.htt.bms.testcontroller;

import com.htt.bms.utils.JWTUtils;
import com.htt.bms.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 侯婷婷
 * @version 1.0
 * @description 测试jwt令牌
 */
@Slf4j
@RestController
public class LoginController {

    @GetMapping("/test/login")
    public Result login(String username, String password){
        log.info("用户登录信息：{}，{}", username, password);

        //验证登录信息
        //登录成功后，生成jwt令牌
        if (!username.isEmpty() && !password.isEmpty()){
            Map<String, Object> claims = new HashMap<>();
            claims.put("username", username);
            claims.put("password", password);

            String token = JWTUtils.generateJwt(claims);
            return Result.success(token);
        }

        return Result.error("500", "用户录失败");
    }
}
